package com.fengniao.goods.config;

import entity.Result;
import exceptions.DataBaseNoResultException;
import exceptions.DataBaseOperationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lanhai
 * @date 2021/7/4 20:52
 */
@ControllerAdvice
@RestController
public class BaseExceptionResolver {

    /**
     * 默认异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    /**
     * 数据库操作出现异常
     * @param e
     * @return
     */
    @ExceptionHandler(DataBaseOperationException.class)
    public Result dataBaseOperationException(DataBaseOperationException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    /**
     * 从数据库中未查到信息
     * @param e
     * @return
     */
    @ExceptionHandler(DataBaseNoResultException.class)
    public Result dataBaseNoResultException(DataBaseNoResultException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }



}
